<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>多边形</title>
  <style>
    .mycanvas{
      border:solid 2px black;
    }
  </style>
</head>
<body>
  <canvas class="mycanvas" width="1200" height="800"></canvas>
  <script>
    
    var mycanvas = document.querySelector('.mycanvas');
    var ctx = mycanvas.getContext('2d');

    ctx.beginPath();
        
    //设置画布中心点
    ctx.translate(mycanvas.width/2,mycanvas.height/2);
    //以(0,0)旋转画布

    //正三角形
    ctx.beginPath();
    ctx.moveTo(0,-100);
    ctx.rotate(2*Math.PI/3);
    ctx.lineTo(0,-100);

    ctx.rotate(2*Math.PI/3);
    ctx.lineTo(0,-100);

    ctx.closePath();

    ctx.lineWidth = 4;
    ctx.strokeStyle = "purple";
    ctx.stroke();



  </script>
</body>
</html>